﻿using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace WeDonekRpc.ApiGateway.Json
{
    internal class LongArrayToString : JsonConverter<long[]>
    {
        public override long[] Read ( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options )
        {
            return null;
        }

        public override void Write ( Utf8JsonWriter writer, long[] array, JsonSerializerOptions options )
        {
            if ( array == null )
            {
                writer.WriteNullValue();
                writer.Flush();
                return;
            }
            else if ( array.Length == 0 )
            {
                writer.WriteStartArray();
                writer.WriteEndArray();
            }
            else
            {
                writer.WriteStartArray();
                foreach ( long i in array )
                {
                    writer.WriteStringValue(i.ToString());
                }
                writer.WriteEndArray();
            }
        }
    }
}
